/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxValue = function (grid) {
	// 判空
	if (!grid.length) {
		return 0;
	}
	// 获取行列
	let row = grid.length, col = grid[0].length;
	// 初始化第一行和第一列的dp，也就是grid
	for (let i = 1; i < col; i++) {
		grid[0][i] += grid[0][i - 1];
	}
	for (let i = 1; i < row; i++) {
		grid[i][0] += grid[i - 1][0];
	}
	for (let i = 1; i < row; i++) {
		for (let j = 1; j < col; j++) {
			grid[i][j] += Math.max(grid[i - 1][j], grid[i][j - 1]);
		}
	}
	return grid[row - 1][col - 1];
};